package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.asset.AssetInventoryProductDto;
import com.java110.intf.goods.IAssetInventoryProductInnerServiceSMO;
import com.java110.mall.goods.dao.IAssetInventoryProductServiceDao;
import com.java110.po.assetInventory.AssetInventoryProductPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 资产盘点明细内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class AssetInventoryProductInnerServiceSMOImpl extends BaseServiceSMO implements IAssetInventoryProductInnerServiceSMO {

    @Autowired
    private IAssetInventoryProductServiceDao assetInventoryProductServiceDaoImpl;


    @Override
    public int saveAssetInventoryProduct(@RequestBody AssetInventoryProductPo assetInventoryProductPo) {
        int saveFlag = 1;
        assetInventoryProductServiceDaoImpl.saveAssetInventoryProductInfo(BeanConvertUtil.beanCovertMap(assetInventoryProductPo));
        return saveFlag;
    }

    @Override
    public int saveAssetInventoryProducts(@RequestBody List<AssetInventoryProductPo> assetInventoryProductPos) {

        Map info = new HashMap();
        info.put("assetInventoryProductPos",assetInventoryProductPos);
        return assetInventoryProductServiceDaoImpl.saveAssetInventoryProductInfos(info);

    }

    @Override
    public int updateAssetInventoryProduct(@RequestBody AssetInventoryProductPo assetInventoryProductPo) {
        int saveFlag = 1;
        assetInventoryProductServiceDaoImpl.updateAssetInventoryProductInfo(BeanConvertUtil.beanCovertMap(assetInventoryProductPo));
        return saveFlag;
    }

    @Override
    public int deleteAssetInventoryProduct(@RequestBody AssetInventoryProductPo assetInventoryProductPo) {
        int saveFlag = 1;
        assetInventoryProductPo.setStatusCd("1");
        assetInventoryProductServiceDaoImpl.updateAssetInventoryProductInfo(BeanConvertUtil.beanCovertMap(assetInventoryProductPo));
        return saveFlag;
    }

    @Override
    public List<AssetInventoryProductDto> queryAssetInventoryProducts(@RequestBody AssetInventoryProductDto assetInventoryProductDto) {

        //校验是否传了 分页信息

        int page = assetInventoryProductDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            assetInventoryProductDto.setPage((page - 1) * assetInventoryProductDto.getRow());
        }

        List<AssetInventoryProductDto> assetInventoryProducts = BeanConvertUtil.covertBeanList(assetInventoryProductServiceDaoImpl.getAssetInventoryProductInfo(BeanConvertUtil.beanCovertMap(assetInventoryProductDto)), AssetInventoryProductDto.class);

        return assetInventoryProducts;
    }


    @Override
    public int queryAssetInventoryProductsCount(@RequestBody AssetInventoryProductDto assetInventoryProductDto) {
        return assetInventoryProductServiceDaoImpl.queryAssetInventoryProductsCount(BeanConvertUtil.beanCovertMap(assetInventoryProductDto));
    }

    public IAssetInventoryProductServiceDao getAssetInventoryProductServiceDaoImpl() {
        return assetInventoryProductServiceDaoImpl;
    }

    public void setAssetInventoryProductServiceDaoImpl(IAssetInventoryProductServiceDao assetInventoryProductServiceDaoImpl) {
        this.assetInventoryProductServiceDaoImpl = assetInventoryProductServiceDaoImpl;
    }
}
